package com.example.administrator.myfragment;

import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

/**
 * Created by wq on 2018/10/30.
 */
public class FourFragment extends Fragment {

    private boolean ishidden = false;
    private TextView tv;
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View messageLayout = inflater.inflate(R.layout.fragment, container, false);
        tv=(TextView) messageLayout.findViewById(R.id.message);
        tv.setText("第四页");


        String message = getArguments().getString("message");
        Log.d("======FourFragment",message);
        return messageLayout;
    }


    @Override
    public void onHiddenChanged(boolean hidden) {
//        super.onHiddenChanged(hidden);
        this.ishidden = hidden;
        if (!hidden) {
            Log.d("=====FourFragment","onHiddenChanged");
        }
    }
    /**
     * Fragment是否可见
     * @return
     */
    public boolean isFragmentVisible() {
        if ( !ishidden) {
            return true;
        }
        return false;
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);

        Log.d("======FourFragment","onAttach");
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.d("======FourFragment","onCreate");
    }

    @Override
    public void onStart() {
        super.onStart();
        Log.d("======FourFragment","onStart");
    }

    @Override
    public void onResume() {
        super.onResume();
        Log.d("======FourFragment","onResume");
        if (isFragmentVisible()) {  //
            Log.d("======FourFragment","onResume=====================only");
        }
    }

    @Override
    public void onPause() {
        super.onPause();
        Log.d("======FourFragment","onPause");
    }

    @Override
    public void onStop() {
        super.onStop();
        Log.d("======FourFragment","onStop");
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        Log.d("======onDestroy","onDestroy");
    }
}
